{% macro aws_x86_64(max, max_starting, max_prealloc, spot=False) %}
aws_x86_64_{% if spot %}spot{% else %}normal{% endif %}_{% if devel %}dev{% else %}prod{% endif %}:
    max: {{ max }}
    max_starting: {{ max_starting }}
    max_prealloc: {{ max_prealloc }}
    tags:
    - name: copr_builder
{% if spot %}
      priority: -5
{% else %}
      priority: -10
{% endif %}
    - arch_x86_64
    - arch_x86_64_native
    - arch_i386
    - arch_i386_native
    - arch_i586
    - arch_i586_native
    - arch_i686
    - arch_i686_native
    - arch_armhfp
    - arch_armhfp_emulated
    - arch_noarch
    - aws
{% if spot %}
    cmd_new: copr-resalloc-aws-new-x86_64 --spot-price 0.156
{% else %}
    cmd_new: copr-resalloc-aws-new-x86_64
{% endif %}
    cmd_delete: "/var/lib/resallocserver/resalloc_provision/vm-delete"
    cmd_livecheck: "resalloc-check-vm-ip"
    cmd_release: "/var/lib/resallocserver/resalloc_provision/vm-release"
    livecheck_period: 180
    reuse_opportunity_time: 180
    reuse_max_count: 8
    reuse_max_time: 1800
{% endmacro %}

{% macro aws_aarch64(max, max_starting, max_prealloc, spot=False) %}
aws_aarch64_{% if spot %}spot{% else %}normal{% endif %}_{% if devel %}dev{% else %}prod{% endif %}:
    max: {{ max }}
    max_starting: {{ max_starting }}
    max_prealloc: {{ max_prealloc }}
    tags:
    - copr_builder
    - arch_aarch64
    - arch_aarch64_native
    - aws
{% if spot %}
    cmd_new: copr-resalloc-aws-new-aarch64 --spot-price 0.102
{% else %}
    cmd_new: copr-resalloc-aws-new-aarch64
{% endif %}
    cmd_delete: "/var/lib/resallocserver/resalloc_provision/vm-delete"
    cmd_livecheck: "resalloc-check-vm-ip"
    cmd_release: "/var/lib/resallocserver/resalloc_provision/vm-release"
    livecheck_period: 180
    reuse_opportunity_time: 180
    reuse_max_count: 8
    reuse_max_time: 1800
{% endmacro %}

# x86_64 hypervisors
{% for hv in ["01", "02", "03", "04"] %}
{% if "x86_hypervisor_" + hv in builders %}
copr_hv_x86_64_{{ hv }}_{% if devel %}dev{% else %}prod{% endif %}:
    max: {{ builders["x86_hypervisor_" + hv]["x86_64"][0] }}
    max_starting: {{ builders["x86_hypervisor_" + hv]["x86_64"][1] }}
    max_prealloc: {{ builders["x86_hypervisor_" + hv]["x86_64"][2] }}
    tags:
    - copr_builder
    - arch_noarch
    - arch_x86_64
    - arch_x86_64_native
    - arch_i386
    - arch_i386_native
    - arch_i586
    - arch_i586_native
    - arch_i686
    - arch_i686_native
    - arch_armhfp
    - arch_armhfp_emulated
    - hypervisor
    - hypervisor_x86_64
    - hypervisor_x86_64_{{ hv }}
    cmd_new: "/var/lib/resallocserver/provision/libvirt-new --ram-size 16384 --swap-vol-size 168"
    cmd_delete: "/var/lib/resallocserver/resalloc_provision/vm-delete"
    cmd_livecheck: "resalloc-check-vm-ip"
    cmd_release: "/var/lib/resallocserver/resalloc_provision/vm-release"
    cmd_list: "/var/lib/resallocserver/provision/libvirt-list"
    livecheck_period: 180
    reuse_opportunity_time: 180
    reuse_max_count: 8
    reuse_max_time: 1800
{% else %}
#
# x86_hypervisor_{{ hv }} not configured in group_vars
#
{% endif %}
{% endfor %}

# Power8 hypervisors
{% for hv in ["01", "02", "03"] %}
{% if "ppc64le_hypervisor_" + hv in builders %}

copr_hv_ppc64le_{{ hv }}_{% if devel %}dev{% else %}prod{% endif %}:
    max: {{ builders["ppc64le_hypervisor_" + hv]["ppc64le"][0] }}
    max_starting: {{ builders["ppc64le_hypervisor_" + hv]["ppc64le"][1] }}
    max_prealloc: {{ builders["ppc64le_hypervisor_" + hv]["ppc64le"][2] }}
    tags:
    - copr_builder
    - name: arch_noarch
      priority: -8
    - arch_ppc64le
    - arch_ppc64le_native
    - hypervisor
    - hypervisor_ppc64le
    - hypervisor_ppc64le_{{ hv }}
    - arch_power8
    cmd_new: "/var/lib/resallocserver/provision/libvirt-new --swap-vol-size 168"
    cmd_delete: "/var/lib/resallocserver/resalloc_provision/vm-delete"
    cmd_livecheck: "resalloc-check-vm-ip"
    cmd_release: "/var/lib/resallocserver/resalloc_provision/vm-release"
    cmd_list: "/var/lib/resallocserver/provision/libvirt-list"
    livecheck_period: 180
    reuse_opportunity_time: 180
    reuse_max_count: 8
    reuse_max_time: 1800

{% endif %}
{% endfor %}


# Power9 hypervisors
{% for hv in ["01", "02", "03"] %}
{% if "p09_hypervisor_" + hv in builders %}

copr_p09_{{ hv }}_{% if devel %}dev{% else %}prod{% endif %}:
    max: {{ builders["p09_hypervisor_" + hv]["ppc64le"][0] }}
    max_starting: {{ builders["p09_hypervisor_" + hv]["ppc64le"][1] }}
    max_prealloc: {{ builders["p09_hypervisor_" + hv]["ppc64le"][2] }}
    tags:
    - copr_builder
    - name: arch_noarch
      priority: -8
    - arch_ppc64le
    - arch_ppc64le_native
    - hypervisor
    - hypervisor_p09
    - hypervisor_p09_{{ hv }}
    - arch_power9
    # The Power9 machine has 160 threads.  The bottleneck is certainly small
    # disk, so try to waste the CPUs appropriately.
    cmd_new: "/var/lib/resallocserver/provision/libvirt-new --cpu-count 5 --ram-size 16384 --swap-vol-size 168"
    cmd_delete: "/var/lib/resallocserver/resalloc_provision/vm-delete"
    cmd_livecheck: "resalloc-check-vm-ip"
    cmd_release: "/var/lib/resallocserver/resalloc_provision/vm-release"
    cmd_list: "/var/lib/resallocserver/provision/libvirt-list"
    livecheck_period: 180
    reuse_opportunity_time: 180
    reuse_max_count: 8
    reuse_max_time: 1800

{% endif %}
{% endfor %}

# Z Cloud instances
copr_ibm_cloud_s390x_tokyo_{% if devel %}dev{% else %}prod{% endif %}:
  max: {{ builders.ibm_cloud_tokyo.s390x[0] }}
  max_prealloc: {{ builders.ibm_cloud_tokyo.s390x[1] }}
  max_starting: {{ builders.ibm_cloud_tokyo.s390x[2] }}
  tags:
    - copr_builder
    - name: arch_noarch
      priority: -30
    - arch_s390x
    - arch_s390x_native
    - ibm_cloud
    - tokyo
  cmd_new: '/var/lib/resallocserver/resalloc_provision/ibm-cloud-vm --log-level debug create "$RESALLOC_NAME"'
  cmd_delete: "/var/lib/resallocserver/resalloc_provision/vm-delete"
  cmd_livecheck: "resalloc-check-vm-ip"
  cmd_release: "/var/lib/resallocserver/resalloc_provision/vm-release"
  cmd_list: "/var/lib/resallocserver/resalloc_provision/ibm-cloud-list-vms"
  livecheck_period: 180
  reuse_opportunity_time: 180
  reuse_max_count: 8
  reuse_max_time: 1800

# Power9 VMs in openpower-controller.osuosl.org
copr_osuosl_p09_{% if devel %}dev{% else %}prod{% endif %}:
{% if devel %}
  max: 3
  max_prealloc: 1
  max_starting: 1
{% else %}
  max: 15
  max_prealloc: 6
  max_starting: 4
{% endif %}
  tags:
    - copr_builder
    - name: arch_noarch
      priority: -25
    - name: arch_ppc64le
      priority: -10
    - arch_ppc64le_native
    - in_osuosl
    - name: arch_power9
      priority: -10
  cmd_new: '/var/lib/resallocserver/resalloc_provision/osuosl-vm'
  cmd_delete: "/var/lib/resallocserver/resalloc_provision/vm-delete"
  cmd_livecheck: "resalloc-check-vm-ip"
  cmd_release: "/var/lib/resallocserver/resalloc_provision/vm-release"
  cmd_list: '/var/lib/resallocserver/resalloc_provision/osuosl-list'
  livecheck_period: 180
  reuse_opportunity_time: 180
  reuse_max_count: 8
  reuse_max_time: 1800

{{ aws_x86_64(builders.aws.x86_64[0], builders.aws.x86_64[1],
              builders.aws.x86_64[2])
}}
{{ aws_aarch64(builders.aws.aarch64[0], builders.aws.aarch64[1],
               builders.aws.aarch64[2])
}}

{{ aws_x86_64(builders.aws_spot.x86_64[0], builders.aws_spot.x86_64[1],
              builders.aws_spot.x86_64[2], True)
}}
{{ aws_aarch64(builders.aws_spot.aarch64[0], builders.aws_spot.aarch64[1],
               builders.aws_spot.aarch64[2], True)
}}
